package com.bailan.foreat.controller;


import com.bailan.foreat.service.StoreService;
import com.bailan.foreat.vo.EsStore;
import com.bailan.foreat.vo.StoreVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ste
 * @since 2023-02-21 07:50:43
 */
@Controller
@RequestMapping("/store")
public class StoreController {


    @Autowired
    StoreService storeService;

    @RequestMapping("select")
    @ResponseBody
    public Page select(
            @RequestParam(defaultValue = "1") Integer currentPage,
            @RequestParam(defaultValue = "2") Integer pageSize,
            @RequestParam(defaultValue = "") String keyName,
            @RequestParam(defaultValue = "0") Integer keyType
    ) {
        Page storePage;
        if ("".equals(keyName) && keyType == 0) {
            storePage = storeService.selectAll(currentPage, pageSize);
        } else {
            Page<EsStore> esStorePage = storeService.searchByES(currentPage, pageSize, keyName, keyType);
            storePage = esStorePage;
        }
        return storePage;
    }


    @RequestMapping("toStoreMenu")
    public String toStoreMenu(Integer storeId, Model model) {
        model.addAttribute("storeId", storeId);
        return "storemenu";
    }

    @RequestMapping("queryDetails")
    @ResponseBody
    public StoreVo queryDetails(Integer storeId){
        StoreVo storeVo = storeService.queryDetails(storeId);
        return storeVo;
    }
}

